package com.margo.project.web.validator.controller;

import java.util.List;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.margo.project.web.validator.model.MargoValidatorVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * https://www.jianshu.com/p/a524a4587d4a
 * @author fangxingbang
 *
 */
@Api(tags={"validator"})
@Controller
@RequestMapping("/validator")
public class MargoValidatorController {

	/**
	 * BeanPropertyBindingResult
	 * FieldError
	 * @param margoValidatorVO
	 * @param result
	 * @return
	 */
	@ApiOperation(value="发送", notes="发送解析文本", produces="application/x-www-form-urlencoded")
	@PostMapping("/save")
	@ResponseBody
	public int save(@Valid MargoValidatorVO margoValidatorVO, BindingResult result) {
		if (result.hasErrors()) {
			List<ObjectError> lstResult = result.getAllErrors();
			for (ObjectError objectError : lstResult) {
				System.out.println(objectError.getObjectName()+":"+objectError.getCode()+":"+objectError.getDefaultMessage());
			}
			System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&检验有问题");
		}
		return 1;
	}
}
